<!DOCTYPE html>
<html lang="zh-CN" xmlns:th=http://www.thymeleaf.org>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>ATC | Main</title>
    <link href="inspinia/css/bootstrap.min.css" rel="stylesheet">
    <link rel="stylesheet" th:href="@{inspinia/font-awesome-4.7.0/css/font-awesome.min.css}"/>
    <!-- Toastr style -->
    <link href="inspinia/css/plugins/toastr/toastr.min.css" rel="stylesheet">
    <!-- Gritter -->
    <link href="inspinia/js/plugins/gritter/jquery.gritter.css" rel="stylesheet">

    <link href="inspinia/css/animate.css" rel="stylesheet">
    <link href="inspinia/css/style.css" rel="stylesheet">
    <link th:href="@{inspinia/css/jquery-confirm.css}" rel="stylesheet">
</head>
<body class="gray-bg">
<div id="wrapper">
    <div id="page-wrapper" class="gray-bg">
        <div class="wrapper wrapper-content">
            <div class="row">
                <div class="col-lg-3">
                    <div class="ibox float-e-margins">
                        <div class="ibox-content mailbox-content">
                            <div class="file-manager">
                                <a id="startCodeA" href="javascript:void(0);" class="btn btn-block btn-danger compose-mail"
                                   th:onclick="'javascript:startCode();'">开始生成</a>
                                <a id="startCodeB" href="javascript:void(0);" class="btn btn-block btn-warning compose-mail"
                                   th:onclick="'javascript:decode();'">撤销生成</a>
                                <a class="btn btn-block btn-primary " href="config">修改配置</a>
                                <div class="space-25"></div>
                                <h5>文件列表</h5>
                                <ul class="folder-list m-b-md" style="padding: 0">
                                    <li><a href="javascript:void(0);"><i class="fa fa-file-text-o"></i> SpringMVC
                                        Controller</a></li>
                                    <li><a href="javascript:void(0);"><i class="fa fa-file-text-o"></i> Service</a></li>
                                    <li><a href="javascript:void(0);"><i class="fa fa-file-text-o"></i> ServiceImpl</a>
                                    </li>
                                    <li><a href="javascript:void(0);"><i class="fa fa-file-text-o"></i> Dao</a></li>
                                    <li><a href="javascript:void(0);"><i class="fa fa-file-text-o"></i> Mybatis Mapping</a>
                                    </li>
                                    <li><a href="javascript:void(0);"><i class="fa fa-file-text-o"></i> HTML/JSP</a>
                                    </li>
                                    <li><a href="javascript:void(0);"><i class="fa fa-file-text-o"></i>
                                        ExtMVC-Application</a></li>
                                    <li><a href="javascript:void(0);"><i class="fa fa-file-text-o"></i>
                                        ExtMVC-Controller</a></li>
                                    <li><a href="javascript:void(0);"><i class="fa fa-file-text-o"></i> ExtMVC-Model</a>
                                    </li>
                                    <li><a href="javascript:void(0);"><i class="fa fa-file-text-o"></i> ExtMVC-Store</a>
                                    </li>
                                    <li><a href="javascript:void(0);"><i class="fa fa-file-text-o"></i> ExtMVC-View</a>
                                    </li>
                                </ul>
                                <!--<h5>状态描述</h5>-->
                                <!--<ul class="category-list" style="padding: 0">-->
                                <!--<li><a href="#"> <i class="fa fa-circle text-navy"></i> 成功 </a></li>-->
                                <!--<li><a href="#"> <i class="fa fa-circle text-danger"></i> 失败</a></li>-->
                                <!--<li><a href="#"> <i class="fa fa-circle text-info"></i> 提示</a></li>-->
                                <!--<li><a href="#"> <i class="fa fa-circle text-warning"></i> 警告</a></li>-->
                                <!--</ul>-->
                                <div class="clearfix"></div>
                            </div>
                        </div>
                    </div>
                </div>
                <div class="col-lg-9 col-small-9 animated fadeInRight">
                    <div class="mail-box-header">
                        <div class="pull-right tooltip-demo">
                            <a href="javascript:void(0);" th:onclick="'javascript:clearConsole()'"
                               class="btn btn-white btn-sm" data-toggle="tooltip"
                               data-placement="top" title="清空消息"><i class="fa fa-trash-o"></i> </a>
                        </div>
                        <h2>
                            状态消息
                        </h2>
                    </div>
                    <div id="console-main-box" class="mail-box"
                         style="height:400px;min-height: 400px;max-height: 400px;overflow: auto;">
                        <div id="console-box" class="mail-body">

                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
<!-- Mainly scripts -->
<script src="inspinia/js/jquery-3.1.1.min.js"></script>
<script src="inspinia/js/bootstrap.min.js"></script>
<script src="inspinia/js/plugins/pace/pace.min.js"></script>
<!-- Toastr -->
<script src="inspinia/js/plugins/toastr/toastr.min.js"></script>
<!--jquery confirm-->
<script src="inspinia/js/jquery-confirm.js"></script>
<!-- socket.io -->
<script src="inspinia/js/socket.io.js"></script>
<script>
    //<![CDATA[
    var clientid = 'clientid';
    var socket = io.connect(getHostIP()+':8002?clientid=' + clientid);

    socket.on('connect', function () {
        output('<span class="connect-msg"> 成功连接到服务器，等待接收消息</span>');
    });

    socket.on('messageevent', function (data) {
        output(data.msgContent);
    });

    socket.on('disconnect', function () {
        output('<span class="disconnect-msg">连接已关闭！</span>');
    });

    function decode() {
        $.confirm({
            title: '警告!',
            content: '即将根据设置撤销自动创建的文件！确定吗？',
            confirmButton: '确认开始',
            cancelButton: '取消',
            confirmButtonClass: 'btn-danger',
            cancelButtonClass: 'btn-info',
            keyboardEnabled: true,
            confirm: function () {
                $.ajax({
                    url: 'startCode?flag=1',
                    type: 'GET',
                    timeout: 3000000,
                    dataType: 'json',
                    data: {_method: 'GET'},
                    success: function (result) {
                        if(result.flag) {
                        }else {
                            $.confirm({
                                title: '出错了', // hides the title.
                                content:result.msg,
                                cancelButton: '确定',
                                confirmButton: false, // hides the confirm button.
                                closeIcon: false // hides the close icon.
                            });
                        }
                    },
                    failure: function () {
                        $.confirm({
                            title: '出错了', // hides the title.
                            content:'暂时无法访问服务器，请稍后重试！',
                            cancelButton: '确定',
                            confirmButton: false, // hides the confirm button.
                            closeIcon: false, // hides the close icon.
                            content: false // hides content block.
                        });
                    }
                });
            }
        });
    }

    function startCode() {
        $.confirm({
            title: '警告!',
            content: '即将根据设置开始自动创建文件，会覆盖之前自动创建的文件！确定吗？',
            confirmButton: '确认开始',
            cancelButton: '取消',
            confirmButtonClass: 'btn-danger',
            cancelButtonClass: 'btn-info',
            keyboardEnabled: true,
            confirm: function () {
                $.ajax({
                    url: 'startCode',
                    type: 'GET',
                    timeout: 3000000,
                    dataType: 'json',
                    data: {_method: 'GET'},
                    success: function (result) {
                        if(result.flag) {
                        }else {
                            $.confirm({
                                title: '出错了', // hides the title.
                                content:result.msg,
                                cancelButton: '确定',
                                confirmButton: false, // hides the confirm button.
                                closeIcon: false // hides the close icon.
                            });
                        }
                    },
                    failure: function () {
                        $.confirm({
                            title: '出错了', // hides the title.
                            content:'暂时无法访问服务器，请稍后重试！',
                            cancelButton: '确定',
                            confirmButton: false, // hides the confirm button.
                            closeIcon: false, // hides the close icon.
                            content: false // hides content block.
                        });
                    }
                });
            }
        });
    }

    function clearConsole() {
        $('#console-box').remove();
        $('#console-main-box').append("<div id=\"console-box\" class=\"mail-body\"></div>");
    }

    function sendDisconnect() {
        socket.disconnect();
    }

    // function sendMessage() {
    //     var message = $('#msg').val();
    //     $('#msg').val('');
    //
    //     var jsonObject = {
    //         sourceClientId: clientid,
    //         targetClientId: targetClientId,
    //         msgType: 'chat',
    //         msgContent: message
    //     };
    //     socket.emit('messageevent', jsonObject);
    // }

    function output(message) {
        var currentTime = "<span class='time'>" + getNowFormatDate() + "</span>";
        var element = $("<div>" + currentTime + " " + message + "</div>");
        $('#console-box').prepend(element);
    }


    function getNowFormatDate() {
        var date = new Date();
        var seperator1 = "-";
        var seperator2 = ":";
        var month = date.getMonth() + 1;
        var strDate = date.getDate();
        var strSecond = date.getSeconds();
        var strHour = date.getHours();
        var strMinu = date.getMinutes();
        if (month >= 1 && month <= 9) {
            month = "0" + month;
        }
        if (strDate >= 0 && strDate <= 9) {
            strDate = "0" + strDate;
        }
        if (strSecond >= 0 && strSecond <= 9) {
            strSecond = "0" + strSecond;
        }
        if (strHour >= 0 && strHour <= 9) {
            strHour = "0" + strHour;
        }
        if (strMinu >= 0 && strMinu <= 9) {
            strMinu = "0" + strMinu;
        }

        var currentdate = date.getFullYear() + seperator1 + month + seperator1 + strDate
            + " " + strHour + seperator2 + strMinu
            + seperator2 + strSecond + "：";
        return currentdate;
    }

    /**
     * 获取项目根路径
     */
    function getRootPath() {
        var strFullPath = window.document.location.href;
        var strPath = document.location.pathname;
        if(strPath == null || strPath =='/') {
            return strFullPath;
        }else {
            var pos = strFullPath.indexOf(strPath);
            var prePath = strFullPath.substring(0,pos);
            // var postPath = strPath.substring(0,strPath.substring(1).indexOf("/")+1);
            return prePath;
        }
    }
    function getHostIP() {
        var hrefs = getRootPath();
        var temp = hrefs.substring(6);
        return hrefs.substring(0,temp.indexOf(":")+6);
    }
    //]]>
</script>
</body>

</html>